*===============================================================================
*Firm and Country Embedded Productivity (Alviarez, Cravino and Ramondo) 
*Headings to indicate the conditions for regressions
*Last Modified by Vanessa Alviarez 02/2022
*===============================================================================
/*
*** Check whether we are using this locals below ***
$nonmarket 
$cont_firms
$cont_firms2
$numctry
$pctiles
*/





*=======================================================Below is for 04/13/2022==========================================================

****** check baseline (esto deberia dar lo mismo que en el paper)********
if "`heading'"=="base_check" {
*-----------------------------------------------------------
local ending "_all" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_check" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq"' 
}
*


****** Substracting exports ********
if "`heading'"=="base_exclexp_alt" {

*-----------------------------------------------------------
local ending "_all"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_exclexp_alt" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp2 includes AU, DK and NO*/
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_alt)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  ""  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq "' 
}


if "`heading'"=="base_exclexp" {

*-----------------------------------------------------------
local ending "_all"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_exclexp" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp2 includes AU, DK and NO*/
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  ""  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq "' 
}


*********** AGE 10 (This erase not only the MNCs with 10 or more years of experience. We are only keeping experience affiliates for any parent.) ***********
if "`heading'"=="base_aboveage10" {

*-----------------------------------------------------------
local ending "_all"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_aboveage10" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp2 includes AU, DK and NO*/
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  ""  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq "' 
}
*


*********** AGE 5 (This erase not only the MNCs with 5 or more years of experience. We are only keeping experience affiliates for any parent.) ***********
if "`heading'"=="base_aboveage15" {

*-----------------------------------------------------------
local ending "_all"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_aboveage15" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp2 includes AU, DK and NO*/
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  ""  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq "' 

}
*




***********************BASELINE (no parents, sample 4)************************

if "`heading'"=="base_woparent" {
*-----------------------------------------------------------
local ending "" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq "' 
}
*

***********************BASELINE with the new KLEMS (no parents, sample 4)************************

if "`heading'"=="base_woparent_new" {
*-----------------------------------------------------------
local ending "_sawb" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_new" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_new)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq "' 
}
*

*** Note (for the headings above and below this line) --- these are not using orbis when creating the variable of interest. Therefore the ending is "not really in use" in this case". By convension we selected ending "_sawb in these cases"
*** Notice that if we filter the data on observations having more than one variable (non-missing, nonzero) even if not using orbis as denominator, in these cases the restriction (e.g. _sawb also goes into the title)
if "`heading'"=="base_woparent_sawbnew" {
*-----------------------------------------------------------
local ending "_sawb" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_sawbnew" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_new)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_new!=. & sin_sales_ko_new!=0)  & (sin_comp_ko_new!=. & sin_comp_ko_new!=0)   "'
}
*

if "`heading'"=="base_woparent_saemnew" {
*-----------------------------------------------------------
local ending "_saem" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_saemnew" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_new)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_new!=. & sin_sales_ko_new!=0)  & (sin_emp_ko_new!=. & sin_emp_ko_new!=0)   "'
}
*


if "`heading'"=="base_woparent_old" {
*-----------------------------------------------------------
local ending "_sawb" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_old" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq "' 
}
*

if "`heading'"=="base_woparent_sawbold" {
*-----------------------------------------------------------
local ending "_sawb" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_sawbold" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0)  & (sin_comp_ko!=. & sin_comp_ko!=0)   "'
}
*

***********************BASELINE with the ORBIS in the denominator (06/12/2022)************************


if "`heading'"=="base_woparent_orbis_all`number'" {
*-----------------------------------------------------------
local ending "_all" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_orbis`number'" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis`number')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_orbis`number'!=. & sin_sales_ko_orbis`number'!=0)     "'

}
*


if "`heading'"=="base_woparent_orbis_all" {
*-----------------------------------------------------------
local ending "_all" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0)     "'

}
*



***********************BASELINE with the new KLEMS (new adjustment)************************

*****************   BASELINE (ADJ new)   ******************
if "`heading'"=="base_woparent_adjnew" {
*-----------------------------------------------------------
local ending "_sawb" /**/
local zz naics  /*naics, naics3, naics4*/
local var0a "sales" /*for misallocation exercise only*/
local var0b "comp" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_adjnew" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator'_new)-ln(sin_`var0b'`denominator'_new))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_new!=. & sin_sales_ko_new!=0)  & (sin_comp_ko_new!=. & sin_comp_ko_new!=0)   "'
}
*


*****************   BASELINE (ADJ new) *** EMP ****   ******************
if "`heading'"=="base_woparent_adjnewem" {
*-----------------------------------------------------------
local ending "_saem" /**/
local zz naics  /*naics, naics3, naics4*/
local var0a "sales" /*for misallocation exercise only*/
local var0b "emp" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_adjnew" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator'_new)-ln(sin_`var0b'`denominator'_new))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_new!=. & sin_sales_ko_new!=0)  & (sin_emp_ko_new!=. & sin_emp_ko_new!=0)   "'
}
*



***********************BASELINE with the original KLEMS (old adjustment)************************

*****************   BASELINE (ADJ old)   ******************
if "`heading'"=="base_woparent_adj" {
*-----------------------------------------------------------
local ending "_sawb" /**/
local zz naics  /*naics, naics3, naics4*/
local var0a "sales" /*for misallocation exercise only*/
local var0b "labcost" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_adj" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator')-ln(sin_`var0b'`denominator'))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0)  & (sin_labcost_ko!=. & sin_labcost_ko!=0)   "'
}
*

***********************BASELINE with Orbis (orbis adjustment)************************

*****************   BASELINE (ADJ orbis)   ******************
if "`heading'"=="base_woparent_adjorbis" {
*-----------------------------------------------------------
local ending "_sawb" /**/
local zz naics  /*naics, naics3, naics4*/
local var0a "sales" /*for misallocation exercise only*/
local var0b "labcost" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_adjorbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator'_orbis)-ln(sin_`var0b'`denominator'_orbis))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0)  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'
}
*

***************** EMP *****  BASELINE (ADJ orbis)   ******************
if "`heading'"=="base_woparent_adjorbisem" {
*-----------------------------------------------------------
local ending "_saem" /**/
local zz naics  /*naics, naics3, naics4*/
local var0a "sales" /*for misallocation exercise only*/
local var0b "emp" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_adjorbisem" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator'_orbis)-ln(sin_`var0b'`denominator'_orbis))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0)  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_emp_ko_orbis!=. & sin_emp_ko_orbis!=0) "'
}
*



*************************************************************************
if "`heading'"=="base_misdirect_adjorbis_rho`rhoinitial'" {
*-----------------------------------------------------------
local ending "_sawb" /**/
local zz naics  /*naics, naics3, naics4*/
local var0a "sales" /*for misallocation exercise only*/
local var0b "labcost" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_adjorbis_rho`rhoinitial'" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator'_new)+(`rhoinitial'-1)*(ln(sin_`var0a'`denominator'_orbis)-ln(sin_`var0b'`denominator'_orbis)))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
*global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'!=. & sin_`var0a'`denominator'!=0) & (sin_`var0a'`denominator'_orbis!=. & sin_`var0a'`denominator'_orbis!=0) & (sin_`var0b'`denominator'_orbis!=. & sin_`var0b'`denominator'_orbis!=0) "'
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_new!=. & sin_sales_ko_new!=0)  &  (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'

}
*
if "`heading'"=="base_misdirect_adjorbisem_rho`rhoinitial'" {
*-----------------------------------------------------------
local ending "_saem" /**/
local zz naics  /*naics, naics3, naics4*/
local var0a "sales" /*for misallocation exercise only*/
local var0b "emp" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_adjorbisem_rho`rhoinitial'" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator'_new)+(`rhoinitial'-1)*(ln(sin_`var0a'`denominator'_orbis)-ln(sin_`var0b'`denominator'_orbis)))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
*global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'!=. & sin_`var0a'`denominator'!=0) & (sin_`var0a'`denominator'_orbis!=. & sin_`var0a'`denominator'_orbis!=0) & (sin_`var0b'`denominator'_orbis!=. & sin_`var0b'`denominator'_orbis!=0) "'
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_new!=. & sin_sales_ko_new!=0)  &  (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_emp_ko_orbis!=. & sin_emp_ko_orbis!=0) "'

}
*



if "`heading'"=="base_misdirect_adjnew_rho`rhoinitial'" {
*-----------------------------------------------------------
local ending "_sawb" /**/
local zz naics  /*naics, naics3, naics4*/
local var0a "sales" /*for misallocation exercise only*/
local var0b "labcost" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_adjnew_rho`rhoinitial'" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator'_new)+(`rhoinitial'-1)*(ln(sin_`var0a'`denominator'_new)-ln(sin_`var0b'`denominator'_new)))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
*global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'!=. & sin_`var0a'`denominator'!=0) & (sin_`var0a'`denominator'_orbis!=. & sin_`var0a'`denominator'_orbis!=0) & (sin_`var0b'`denominator'_orbis!=. & sin_`var0b'`denominator'_orbis!=0) "'
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_new!=. & sin_sales_ko_new!=0)  &  (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'

}
*
if "`heading'"=="base_misdirect_adjnewem_rho`rhoinitial'" {
*-----------------------------------------------------------
local ending "_saem" /**/
local zz naics  /*naics, naics3, naics4*/
local var0a "sales" /*for misallocation exercise only*/
local var0b "emp" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_adjnewem_rho`rhoinitial'" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator'_new)+(`rhoinitial'-1)*(ln(sin_`var0a'`denominator'_new)-ln(sin_`var0b'`denominator'_new)))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
*global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'!=. & sin_`var0a'`denominator'!=0) & (sin_`var0a'`denominator'_orbis!=. & sin_`var0a'`denominator'_orbis!=0) & (sin_`var0b'`denominator'_orbis!=. & sin_`var0b'`denominator'_orbis!=0) "'
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_new!=. & sin_sales_ko_new!=0)  &  (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_emp_ko_orbis!=. & sin_emp_ko_orbis!=0) "'

}
*




*======================================================Above is for 04/13/2022==================================================================













***********************BASELINE (no parents, sample 4)************************

if "`heading'"=="base_woparent" {
*-----------------------------------------------------------
local ending "" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq "' 
}
*




***********MISALLOCATION INDIRECT -- KLEMS -- Calculate the dummies making sure each PAIR and ALL are not missing (no parents, sample 4, va/emp/sales/wagebill)************************

*Dummies for all var with KLEMS (LAB, SALES, EMP, VA) 
*  NUM: SALES/EMP**, VA/LAB**, SALES/LAB**, EMP/VA
*  NUM: SALES/EMP/VA**
*  NUM: SALES/VA/LAB**
*  NUM: SALES/EMP/VA/LAB**
*  DEN: as in KLEMS 
				
if "`heading'"=="base_woparent_saem" {
*-----------------------------------------------------------
local ending ""
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_saem" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0 & sin_emp_ko!=. & sin_emp_ko!=0) "'
}
*

if "`heading'"=="base_woparent_vawb" {
*-----------------------------------------------------------
local ending ""
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_vawb" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_va_ko!=. & sin_va_ko!=0 & sin_labcost_ko!=. & sin_labcost_ko!=0) "'
}
*

if "`heading'"=="base_woparent_sawb" {
*-----------------------------------------------------------
local ending ""
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_sawb" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0 & sin_labcost_ko!=. & sin_labcost_ko!=0) "'
}
*

if "`heading'"=="base_woparent_emva" {
*-----------------------------------------------------------
local ending ""
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_emva" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_emp_ko!=. & sin_emp_ko!=0 & sin_va_ko!=. & sin_va_ko!=0) "'
}
*

if "`heading'"=="base_woparent_saemva" {
*-----------------------------------------------------------
local ending ""
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_saemva" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0 & sin_emp_ko!=. & sin_emp_ko!=0 & sin_va_ko!=. & sin_va_ko!=0) "'
}
*


if "`heading'"=="base_woparent_saemvawb" {
*-----------------------------------------------------------
local ending ""
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_saemvawb" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0 & sin_emp_ko!=. & sin_emp_ko!=0 & sin_va_ko!=. & sin_va_ko!=0 & sin_labcost_ko!=. & sin_labcost_ko!=0) "'
}
*


if "`heading'"=="base_woparent_savawb" {
*-----------------------------------------------------------
local ending ""
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_savawb" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0  & sin_va_ko!=. & sin_va_ko!=0  &  sin_labcost_ko!=. & sin_labcost_ko!=0) "'
}
*


*********************MISALLOCATION INDIRECT -- ORBIS (using the denominator from ORBIS calculated with firms for which the GROUP of variable is available)
*****************Calculate the dummies making sure each PAIR and ALL are not missing (no parents, sample 4, va/emp/sales/wagebill)************************

*Dummies for all var with KLEMS (LAB, SALES, EMP, VA) 
*  NUM: SALES/EMP**, VA/LAB**, SALES/LAB**, EMP/VA
*  NUM: SALES/EMP/VA**
*  NUM: SALES/VA/LAB**
*  NUM: SALES/EMP/VA/LAB**
*  DEN: as in KLEMS 


			
if "`heading'"=="base_woparent_orbis_saem" {
*-----------------------------------------------------------
local ending "_saem"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0 & sin_emp_ko_orbis!=. & sin_emp_ko_orbis!=0) "'
}
*


if "`heading'"=="base_woparent_orbis_vawb" {
*-----------------------------------------------------------
local ending "_vawb"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_va_ko_orbis!=. & sin_va_ko_orbis!=0 & sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'
}
*

if "`heading'"=="base_woparent_orbis_sawb" {
*-----------------------------------------------------------
local ending "_sawb"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'

}
*


if "`heading'"=="base_woparent_orbis_emva" {
*-----------------------------------------------------------
local ending "_emva"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_emp_ko_orbis!=. & sin_emp_ko_orbis!=0 & sin_va_ko_orbis!=. & sin_va_ko_orbis!=0) "'
}
*

if "`heading'"=="base_woparent_orbis_saemva" {
*-----------------------------------------------------------
local ending "_saemva"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_orbis!=. & sin_sales_ko!=0 & sin_emp_ko_orbis!=. & sin_emp_ko!=0 & sin_va_ko_orbis!=. & sin_va_ko_orbis!=0) "'
}
*

if "`heading'"=="base_woparent_orbis_savawb" {
*-----------------------------------------------------------
local ending "_savawb"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0  & sin_va_ko_orbis!=. & sin_va_ko_orbis!=0  &  sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'
}
*

if "`heading'"=="base_woparent_orbis_saemvawb" {
*-----------------------------------------------------------
local ending "_saemvawb"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0 & sin_emp_ko_orbis!=. & sin_emp_ko_orbis!=0 & sin_va_ko_orbis!=. & sin_va_ko_orbis!=0 & sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'
}
*



********************* ---NEW--- MISALLOCATION INDIRECT -- ORBIS and KLEMS (1) Klems only revenue and Orbis revenue and compensation *******************************************

if "`heading'"=="base_woparent_klemorbis1_klems" {
*-----------------------------------------------------------
local ending "_sawb"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_klemorbis1_klems" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0) & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'

}
*
if "`heading'"=="base_woparent_klemorbis1_orbis" {
*-----------------------------------------------------------
local ending "_sawb"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_klemorbis1_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0) & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'

}
*



*********************   ---NEW---  MISALLOCATION INDIRECT -- ORBIS and KLEMS (1) Klems revenue and compensation AND Orbis revenue and compensation *******************************************

if "`heading'"=="base_woparent_klemorbis2_klems" {
*-----------------------------------------------------------
local ending "_sawb"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_klemorbis2_klems" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator')" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0)  & (sin_labcost_ko!=. & sin_labcost_ko!=0)  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'
}
*
if "`heading'"=="base_woparent_klemorbis2_orbis" {
*-----------------------------------------------------------
local ending "_sawb"
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_klemorbis2_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0)  & (sin_labcost_ko!=. & sin_labcost_ko!=0)  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'

}






*********************MISALLOCATION DIRECT -- KLEMS-ORBIS (using the denominator from ORBIS calculated with firms for which the GROUP of variable is available)
*****************Calculate the dummies making sure each PAIR and ALL are not missing (no parents, sample 4, va/emp/sales/wagebill)************************
*Dummies with modify LHS with Klems/ORBIS (for all var combinations)
				* Share(LAB, Klems) + rho*[share(SALES, Orbis)-share(LAB, Orbis)]
                * Share(LAB, Klems) + rho*[share(VA, Orbis)-share(LAB, Orbis)]
                * Share(EMP, Klems) + rho*[share(SALES, Orbis)-share(EMP, Orbis)]
                * Share(EMP, Klems) + rho*[share(VA, Orbis)-share(EMP, Orbis)]
*Guide for the arguments this HEAD needs
*local endingargument vawb/sawb/vaem/saem
*local varinterest_a va/sa/va/sa
*local varinterest_a wb/wb/em/em
				
if "`heading'"=="base_misdirect_klemsorbis" {
*-----------------------------------------------------------
local ending "_`endingargument'"
display "`ending'"
local zz naics  /*naics, naics3, naics4*/
local var0a "`varinterest_a'" /*for misallocation exercise only*/
local var0b "`varinterest_b'" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_klemsorbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator')+(`rhoinitial'-1)*(ln(sin_`var0a'`denominator'_orbis)-ln(sin_`var0b'`denominator'_orbis)))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
*global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'!=. & sin_`var0a'`denominator'!=0) & (sin_`var0b'`denominator'!=. & sin_`var0b'`denominator'!=0) & (sin_`var0a'`denominator'_orbis!=. & sin_`var0a'`denominator'_orbis!=0) & (sin_`var0b'`denominator'_orbis!=. & sin_`var0b'`denominator'_orbis!=0) "'
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0)  & (sin_labcost_ko!=. & sin_labcost_ko!=0)  & (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'

}
*

if "`heading'"=="base_misdirect_klemsorbis_b" {
*-----------------------------------------------------------
local ending "_`endingargument'"
display "`ending'"
local zz naics  /*naics, naics3, naics4*/
local var0a "`varinterest_a'" /*for misallocation exercise only*/
local var0b "`varinterest_b'" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_klemsorbis_b" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator')+(`rhoinitial'-1)*(ln(sin_`var0a'`denominator'_orbis)-ln(sin_`var0b'`denominator'_orbis)))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
*global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'!=. & sin_`var0a'`denominator'!=0) & (sin_`var0a'`denominator'_orbis!=. & sin_`var0a'`denominator'_orbis!=0) & (sin_`var0b'`denominator'_orbis!=. & sin_`var0b'`denominator'_orbis!=0) "'
global other_restr  `" keep if isocode!=hq  & (sin_sales_ko!=. & sin_sales_ko!=0)  &  (sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0) & (sin_labcost_ko_orbis!=. & sin_labcost_ko_orbis!=0) "'

}
*

*Dummies with modify LHS with Klems ONLY (for all var combinations)
*-----------------------------------------------------------------------------------

if "`heading'"=="base_misdirect_klemsonly" {
*-----------------------------------------------------------
local ending "_`endingargument'"
local zz naics  /*naics, naics3, naics4*/
local var0a "`varinterest_a'" /*for misallocation exercise only*/
local var0b "`varinterest_b'" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_klemsonly" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0b'`denominator')+`rhoinitial'*(ln(sin_`var0a'`denominator')-ln(sin_`var0b'`denominator')))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'!=. & sin_`var0a'`denominator'!=0) & (sin_`var0b'`denominator'!=. & sin_`var0b'`denominator'!=0)  "'
}
*

if "`heading'"=="base_misdirect_klemsonly_alphactte" {
*-----------------------------------------------------------
local ending "_`endingargument'"
local zz naics  /*naics, naics3, naics4*/
local var0a "`varinterest_a'" /*for misallocation exercise only*/
local var0b "`varinterest_b'" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_klemsonly_alphactte" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0a'`denominator')+(`rhoinitial'-1)*(ln(sin_`var0a')-ln(sin_`var0b')+ln(oalpha_klems)))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'!=. & sin_`var0a'`denominator'!=0) & (sin_`var0b'`denominator'!=. & sin_`var0b'`denominator'!=0)  "'
}
*

*Dummies with modify LHS with ORBIS ONLY (for all var combinations)
*-----------------------------------------------------------------------------------

if "`heading'"=="base_misdirect_orbisonly" {
*-----------------------------------------------------------
local ending "_`endingargument'"
local zz naics  /*naics, naics3, naics4*/
local var0a "`varinterest_a'" /*for misallocation exercise only*/
local var0b "`varinterest_b'" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_orbisonly" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0b'`denominator'_orbis)+`rhoinitial'*(ln(sin_`var0a'`denominator'_orbis)-ln(sin_`var0b'`denominator'_orbis)))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'_orbis!=. & sin_`var0a'`denominator'_orbis!=0) & (sin_`var0b'`denominator'_orbis!=. & sin_`var0b'`denominator'_orbis!=0)  "'
}
*

if "`heading'"=="base_misdirect_orbisonly_adj" {
*-----------------------------------------------------------
local ending "_`endingargument'"
local zz naics  /*naics, naics3, naics4*/
local var0a "`varinterest_a'" /*for misallocation exercise only*/
local var0b "`varinterest_b'" /*for misallocation exercise only*/
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misdirect_orbisonly_adj" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(`rhoinitial'-1)*(ln(sin_`var0a'`denominator')-ln(sin_`var0b'`denominator'))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'_orbis!=. & sin_`var0a'`denominator'_orbis!=0) & (sin_`var0b'`denominator'_orbis!=. & sin_`var0b'`denominator'_orbis!=0)  "'
}
*





















/*

if "`heading'"=="base_woparent_orbisden" {
*-----------------------------------------------------------
local ending "" /**/
local zz naics  /*naics, naics3, naics4*/
local var0 "_`varinterest'" 
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_woparent_salesempva_orbis" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp=sample1= Denmark; samp2 includes AU, DK and NO* and  sample3 includes "TR", "BR", "IN", "DK" */
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "ln(sin`var0'`denominator'_orbis)" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr `" drop if isocode==hq "'
global other_restr2 `" keep if sin_sales_ko_orbis!=. & sin_sales_ko_orbis!=0 & sin_emp_ko_orbis!=. & sin_emp_ko_orbis!=0 & sin_va_ko_orbis!=. & sin_va_ko_orbis!=0 "'
}
*
















***********************MISALLOCATION DIRECT (no parents, sample 4, va/emp/sales/wagebill)************************
*With any two variables*
*---------------------------------------------

if "`heading'"=="base_misall_direct" {
*-----------------------------------------------------------
local ending ""
local zz naics  /*naics, naics3, naics4*/
local var0a "`varinterest_a'" /*for misallocation exercise only*/
local var0b "`varinterest_b'" /*for misallocation exercise only*/
local var0 "`var0a'_`var0b'"
display "`var0a'"
display "`var0b'"
display "`var0'"
local name "_base" /*"_base", "_exclnomark"*/
local name1 "_misall_direct_`var0'" /*"_base", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_exclnomark", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
local title "`zz'_`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' /*drop if sector1=="Non-Market Economy"; drop if sector1==""*/
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE" /*dyadicFE guoFEcte*/
global ind_var dist_sec* lang_sec* /*gdp_pc_curr_in, dist2_sec**/ /*List of variable to use in the gravity equation: distance contig comlang_off colony RTA gdp_pc_curr_in dist2_sec)*/
*local denominator "" /*activated if levels only levels*/
global guoFEonly=0 /*if 1, it replaces the country-sector variables with 1 (one)*/
global LHS "(ln(sin_`var0b'`denominator')+`rhoinitial'*(ln(sin_`var0a'`denominator')-ln(sin_`var0b'`denominator')))" /*levels "ln(sin`var0')"; growth "ln(sin`var0'`denominator')-ln(l`tt'_sin`var0'`denominator')" */
global numctry `" keep if num_ctry>=0 "' /*Keep observations that belong to a GUO that operates in N or more countries*/
global pctiles  `" keep if sin_sales>=0 "'  /* keep if sin_sales>p`pos'_sales [ <= or >]; or keep if sin_sales>=0 */
global other_restr  `" keep if isocode!=hq & (sin_`var0a'`denominator'!=. & sin_`var0a'`denominator'!=0) & (sin_`var0b'`denominator'!=. & sin_`var0b'`denominator'!=0) "'
}
*




